import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Chris
 * Date: 10/8/13
 * Time: 11:31 PM
 * To change this template use File | Settings | File Templates.
 */
public class MergeSort
{
    public static void main(String[] args)
    {
        ArrayList<Integer> myList = new ArrayList<Integer>(10);
        myList.add(-10);
        myList.add(9);
        myList.add(4);
        myList.add(7);
        myList.add(57);
        myList.add(2);
        myList.add(4);
        myList.add(99);
        myList.add(2);
        myList.add(-1845);

        MergeSort.printList(myList);
        MergeSort.sort(myList);
        MergeSort.printList(myList);
    }
    public static void sort(ArrayList<Integer> list)
    {
        for(int i = 0; i< list.size(); i++)
        {
            int curr = list.get(i);
            int j = i;
            while( (j>0)&& list.get(j-1)>curr)
            {
                list.set(j,list.get(j-1));
                j--;
            }
            list.set(j,curr);

        }
    }

    public static void printList(ArrayList<Integer> list)
    {
        for(int i : list)
        {
            System.out.println(i);
        }
    }
}
